package iechecs;

import echecs.Direction;

public class GenerateurConditionnel<R> extends AGenerateur<R> {

    private AGenerateur<Boolean> _test;
    private AGenerateur<R> _then;
    private AGenerateur<R> _else;

  

    public GenerateurConditionnel(AGenerateur<Boolean> test, AGenerateur<R> trueFn, AGenerateur<R> falseFn) {

        if (test == null || trueFn == null || falseFn == null) {
            throw new IllegalArgumentException("Three functors are required");
        }
        _test = test;
        _then = trueFn;
        _else = falseFn;
    }

    public AGenerateur<Boolean> getCondition() {
        return _test;
    }

    public AGenerateur<R> getTrueFunctor() {
        return _then;
    }

    public AGenerateur<R> getFalseFunctor() {
        return _else;
    }

    @Override
    public R gen() {
        return _test.gen() ? _then.gen() : _else.gen();
    }

    @Override
    public String toString() {
        return "ConditionalGenerator[" + _test + "?" + _then + ":" + _else + "]";
    }
}
